<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Full Layout - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<%
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid(){
			$("#easyui-datagrid").datagrid({
				url: 'user_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				
				queryParams: getGueryParams(),
				columns: [[
				    { field:'f_pu_id',checkbox:true}, 
					{field:'f_pu_name',title:'用户账号',align:'center',width:150},
					{field:'f_pu_realName',title:'用户姓名',align:'center',width:150},
					{field:'f_pu_sex',title:'性别',align:'center',width:50,
						formatter:function(value,row,index){
							var sex = "未知";
							if(value==0) {
								sex = "女";
							} else if(value==1) {
								sex = "男";
							} else {
								sex = "未知"
							}
							return sex;
						}
					},
					{field:'f_pu_phone',title:'用户手机',align:'center',width:150},
					{field:'f_pu_address',title:'用户地址',align:'center',width:150},
					{field:'f_pu_status',title:'状态',align:'center',width:100,
						formatter:function(value,row,index){
							var status = "未知";
							if(value==1) {
								status = "有效";
							} else if(value==2) {
								status = "无效";
							} else {
								status = "未知"
							}
							return status;
						}
					},
					{field:'f_pu_createAt',title:'添加时间 ',align:'center',width:150},
					{field:'_parentId',title:'操作',align:'center',width:200,
						formatter:function(value,row,index){
							str ="";
							str= '<limits:uiAuth url="del_user.do"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_pu_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a></limits:uiAuth>';
							str+= '<limits:uiAuth url="user_edit.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_pu_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a></limits:uiAuth>';
				    		str+= '<limits:uiAuth url="user_show.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_pu_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a></limits:uiAuth>';
					    	return str;
				    	}
					}
				
				]],
				singleSelect:false,
				pagination: true,
				//view: detailview,
				pageList: [10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function (data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/index.jsp';
						    return false;
						}});
					}
				}
			});
	    }
		
		function getGueryParams(){
			return {
				f_pu_name:$("#f_pu_name").val(),
				f_pu_realName:$("#f_pu_realName").val()
			};
		}
		
		$(function(){
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
			
			onClickBtnDelete = function(id){
				$.messager.confirm('确认删除记录', '确认删除信息么？', function(r){
					if (r){
						 app_ajax('del_user.do?f_pu_id='+id+'&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>',
						 '',
						 function(msg){
							 if(msg.success){
								 alert("恭喜！删除成功！");
									if (checkAjaxRequestValidity(msg)) {
										gotoSearch($('#easyui-treegrid'));
									}
							  }else{
								  alert("删除异常，请联系管理员");
									if($.isFunction(window.showMessager)){
										window.showMessager(msg.resultTitle,msg.result);
									}
							  }
							 window.location.reload();
						 });
					}
				});
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function _resert(){
			$("#f_pu_name").val("");
			$("#f_pu_realName").val("");
		}
		
		function onpress(){
		var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
   		  	if (event.keyCode == 13){  
      			gotoSearch($('#easyui-treegrid'));
    		}
		}
		
		function edit(id){
			openDialog($("#dlg"),'user_edit.jsp?f_pu_id='+id);
		}
		
		function show(id){
			openDialog($('#dlg'),'user_show.jsp?f_pu_id='+id);
		}
		
		function add(){
			openDialog($('#dlg'),'user_add.jsp');
		}
	</script>
</head>
<body onload="load();">
	<table id="easyui-datagrid" title="管理员列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="right" width="10%">用户账号：</td>
						<td align="left" width="25%"><input name="f_pu_name"
							id="f_pu_name" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="right" width="10%">用户姓名：</td>
						<td align="left" width="25%"><input name="f_pu_realName"
							id="f_pu_realName" style="width: 150px;" onkeydown="onpress();" /></td>
						<td align="left" width="15%"><limits:uiAuth
								url="user_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth></td>
						<td align="left" width="15%"><limits:uiAuth
								url="user_add.jsp">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-add', plain:true" onclick="add()">增加用户</a>
							</limits:uiAuth></td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 470px; padding-top: 0px;"
		data-options="title:'用户账号详情', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
</html>